package chapter;

public class ChuShiHua2 {
    private int side1;
    private int side2;
    private int side3;

    public ChuShiHua2(int side1,int side2,int side3){
        this.side1=side1;
        this.side2=side2;
        this.side3=side3;
        if(!valid()){
            throw new RuntimeException("三角形三边数值不合法！！！");
        }
    }
    private boolean valid(){
        if(!validSide(side1) || !validSide(side2) || !validSide(side3)){
            return false;
        }
        if(side1+side2<side3 || side1+side3<side2 ||side2+side3<side1){
            return false;
        }
        return true;
    }

    private boolean validSide(int side){
        return side>=1&&side<=10;
    }

    @Override
    public String toString(){
        return "["+side1+","+side2+","+side3+"]";
    }

    public static void main(String[] args) {
        ChuShiHua2 c = new ChuShiHua2(3,4,5);
        System.out.println(c);

    }
}
